package com.app.newiptv.helper;


import com.app.newiptv.bean.RequestDto;
import com.app.newiptv.bean.SearchBean;
import com.app.newiptv.bean.SearchResultBean;
import com.app.newiptv.callback.IRequestLisenter;
import com.app.newiptv.callback.RequestCallback;
import com.app.newiptv.utils.OkGoUtil;

/**
 * Created by Shinelon on 2017/9/15.
 */

public class SearchHelper {
    private RequestCallback callback;

    public SearchHelper() {

    }

    public void setCallback(RequestCallback callback) {
        this.callback = callback;
    }

    public void loadData(String url) {
        if (url == null || "".equals(url)) {
            return;
        }
        OkGoUtil<SearchResultBean.DataBean.ListBean> okGoUtil = new OkGoUtil<SearchResultBean.DataBean.ListBean>(SearchResultBean.DataBean.ListBean.class, OkGoUtil.TYPE_ARRAY, new IRequestLisenter() {
            @Override
            public void onSuccessData(RequestDto dto) {
                if (dto != null) {
                    if (callback != null) {
                        callback.onLoadComplete("", 0, dto.getList().size(), dto.getList());
                    }
                }
            }

            @Override
            public void onErrer(int code, String errMsg) {
                if (callback != null) {
                    callback.onFailed(code + "", errMsg);
                }
            }
        });
        okGoUtil.requestPost(url);
    }
}
